#ifndef __SCROLL_CONTAINER_H__
#define __SCROLL_CONTAINER_H__

#include "gofgame/common/ui/Container.h"
#include "gofgame/common/ui/Layout.h"
#include "gofgame/common/Ref.h"
#include "gofgame/common/graphics/Brush.h"

namespace gofgame {
	namespace common {
		namespace ui {

			using namespace gofgame::common::ui;
			using namespace gofgame::common;

			class ScrollContainer : public Container {
			public:
				ScrollContainer();

				virtual float getScrollLeft() const;
				virtual void setScrollLeft(float scrollLeft);
				virtual float getScrollTop() const;
				virtual void setScrollTop(float scrollTop);
				virtual float getScrollWidth() const;
				virtual void setScrollWidth(float scrollWidth);
				virtual float getScrollHeight() const;
				virtual void setScrollHeight(float scrollHeight);

				virtual bool isHorizontalScrollingAllowed() const;
				virtual void setHorizontalScrollingAllowed(bool horizontalScrollingAllowed);
				virtual bool isVerticalScrollingAllowed() const;
				virtual void setVerticalScrollingAllowed(bool verticalScrollingAllowed);
				virtual bool isHorizontalScrollBarAllowed() const;
				virtual void setHorizontalScrollBarAllowed(bool horizontalScrollBarAllowed);
				virtual bool isVerticalScrollBarAllowed() const;
				virtual void setVerticalScrollBarAllowed(bool verticalScrollBarAllowed);

				float getScrollBarWidth() const;
				void setScrollBarWidth(float scrollBarWidth);
				float getScrollLineWidth() const;
				void setScrollLineWidth(float scrollLineWidth);
				const ccColor4F &getScrollLineColor() const;
				void setScrollLineColor(const ccColor4F &scrollLineColor);
				Brush *getHorizontalScrollButtonBrush() const;
				void setHorizontalScrollButtonBrush(Brush *horizontalScrollButtonBrush);
				Brush *getVerticalScrollButtonBrush() const;
				void setVerticalScrollButtonBrush(Brush *verticalScrollButtonBrush);

				virtual void visit() _override;
				
			protected:
				virtual void drawScrollBars();
				virtual CCSize getLayoutSize() const _override;
				virtual void onPostLayout() _override;

				virtual void onTouchBegan(TouchEventArgs &e) _override;
				virtual void onTouchMoved(TouchEventArgs &e) _override;
				virtual void onTouchEnded(TouchEventArgs &e) _override;
				virtual void onTouchCancelled(TouchEventArgs &e) _override;

				virtual bool hideOverflow() const _override _final;

				bool isHorizontalScrollBarVisible() const;
				bool isVerticalScrollBarVisible() const;

			private:
				void calculate();

			private:
				float scrollLeft;
				float scrollTop;
				float scrollWidth;
				float scrollHeight;
				CCPoint previousTouchLocation;
				bool horizontalScrollingAllowed;
				bool verticalScrollingAllowed;
				bool horizontalScrollBarAllowed;
				bool verticalScrollBarAllowed;
				bool horizontalScrollBarVisible;
				bool verticalScrollBarVisible;
				float scrollBarWidth;
				float scrollLineWidth;
				ccColor4F scrollLineColor;
				Ref<Brush> horizontalScrollButtonBrush;
				Ref<Brush> verticalScrollButtonBrush;
			};
		}
	}
}

#endif //__SCROLL_CONTAINER_H__
